package com.twb.message.controller;

import javax.validation.constraints.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.twb.core.base.Result;
import com.twb.core.base.controller.BaseController;
import com.twb.core.base.entity.TwbPageInfo;
import com.twb.core.security.annotation.Auth;
import com.twb.core.util.BeanUtils;
import com.twb.core.util.Results;
import com.twb.message.entity.messageReceivor.MessageReceivor;
import com.twb.message.entity.messageReceivor.dto.GetMessageReceivorByIdDto;
import com.twb.message.entity.messageReceivor.dto.SearchMessageReceivorDto;
import com.twb.message.entity.messageReceivor.vo.SearchMessageReceivorVo;
import com.twb.message.service.IMessageReceivorService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @Title  MessageReceivorController
 * @Description 系统消息接收人信息
 * 
 * @author DHL
 * @date 2021-07-14 09:27:31
 */
@RestController
@RequestMapping("/message/messageReceivor")
@Api(tags = "系统消息接收人信息", value = "MessageReceivorController")
public class MessageReceivorController extends BaseController {
	@Autowired
	IMessageReceivorService messageReceivorService;

	/**
	 * @Title  search
	 * @Description 分页查询
	 * @param vo
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
	@Auth(verifyToken = true, verifyURL = false)
	@GetMapping("/search")
	@ApiOperation(value = "分页查询")
	public Result<TwbPageInfo<SearchMessageReceivorDto>> search(SearchMessageReceivorVo vo) {
		TwbPageInfo<SearchMessageReceivorDto> result = messageReceivorService.searchMessageReceivor(vo);
		return Results.successWithData(result);
	}

	/**
	 * @Title  getById
	 * @Description 根据ID获取详情
	 * @param id
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
	@Auth(verifyToken = true)
	@GetMapping("/getById")
	@ApiOperation(value = "根据ID获取详情")
	public Result<GetMessageReceivorByIdDto> getById(@NotBlank @RequestParam @ApiParam(value = "主键", name = "id", required = true) String id) {
		MessageReceivor messageReceivor = messageReceivorService.getById(id);
		if (messageReceivor == null) {
			return Results.failure("数据不存在");
		}
		GetMessageReceivorByIdDto dto = new GetMessageReceivorByIdDto();
		BeanUtils.copyNotNullProperties(messageReceivor, dto);
		return Results.successWithData(dto);
	}

	/**
	 * @Title  save
	 * @Description 保存信息
	 * @param vo
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/save")
//	@ApiOperation(value="保存信息")
//	public Result<String> save(@Valid SaveMessageReceivorVo vo){
//		int result = messageReceivorService.saveMessageReceivor(vo);
//		if(result>0) {
//			return Results.success("保存成功");
//		}else {
//			return Results.failure("保存失败");
//		}
//	}

	/**
	 * @Title  updateById
	 * @Description 更新信息
	 * @param vo
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/updateById")
//	@ApiOperation(value="更新信息")
//	public Result<String> updateById(@Valid UpdateMessageReceivorByIdVo vo){
//		int result = messageReceivorService.updateMessageReceivorById(vo);
//		if(result>0) {
//			return Results.success("更新成功");
//		}else {
//			return Results.failure("更新失败");
//		}
//	}

	/**
	 * @Title  deleteById
	 * @Description 删除信息
	 * @param id
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/deleteById")
//	@ApiOperation(value="删除信息")
//	public Result<String> deleteById(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键",name="id",required=true)
//			String id){
//		int result = messageReceivorService.deleteMessageReceivorById(id);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  deleteBatchByIds
	 * @Description 批量删除信息
	 * @param ids
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/batchDeleteByIds")
//	@ApiOperation(value="批量删除信息")
//	public Result<String> deleteBatchByIds(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键集合",name="id",required=true)
//			String ids){
//		int result = messageReceivorService.deleteMessageReceivorByIds(ids);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  logicDeleteById
	 * @Description 逻辑删除信息
	 * @param id
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/logicDeleteById")
//	@ApiOperation(value = "逻辑删除信息")
//	public Result<String> logicDeleteById(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键",name="id",required=true)
//			String id){
//		MessageReceivor record = messageReceivorService.get(id);
//		if(null == record) {
//			return Results.failure("信息不存在");
//		}
//		record = new MessageReceivor();
//		record.setId(id);
//		messageReceivorService.setUpdateInfo(record);
//		record.setIsdel(1);
//		int result = messageReceivorService.updateSelective(record);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  logicBatchDeleteByIds
	 * @Description 批量逻辑删除
	 * @param ids
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyToken = true)
//	@PostMapping("/logicBatchDeleteByIds")
//	@ApiOperation(value = "逻辑删除信息")
//	public Result<String> logicBatchDeleteByIds(
//			@NotBlank
//			@RequestParam
//			@ApiParam(value="主键集合",name="id",required=true)
//			String ids){
//		int result = messageReceivorService.logicBatchDeleteMessageReceivorByIds(ids);
//		if(result>0) {
//			return Results.success("删除成功");
//		}else {
//			return Results.failure("删除失败");
//		}
//	}

	/**
	 * @Title  exportExcel
	 * @Description 导出excel
	 * @param exportExcelVo
	 * @param searchVo
	 * @param request
	 * @return
	 * @author DHL
	 * @date 2021-07-14 09:27:31
	 */
//	@Auth(verifyURL=false)
//	@GetMapping("/exportExcel")
//	@ApiOperation(value="导出excel")
//	public void exportExcel(SearchTwbDataDicVo vo, HttpServletResponse response){
//		messageReceivorService.exportExcel(vo, response);
//	}

	/**
	 * @Title searchUserMessageNum
	 * @Description 查询用户待阅消息数
	 * @param userId
	 * @return
	 * @author DHL
	 * @date 2021年7月16日 上午9:54:39
	 */
	@Auth(verifyToken = true, verifyURL = false)
	@GetMapping("/searchUserMessageNum")
	@ApiOperation(value = "查询用户待阅消息数")
	public Result<Integer> searchUserMessageNum(
			@NotBlank @RequestParam @ApiParam(value = "项目主键", name = "projectId", required = true) String projectId,
			@NotBlank @RequestParam @ApiParam(value = "用户主键", name = "userId", required = true) String userId,
			@NotBlank @RequestParam @ApiParam(value = "已读状态", name = "readStatus", required = true) String readStatus) {

		int count = messageReceivorService.searchUserMessageNum(projectId, userId, readStatus);

		return Results.successWithData(count);
	}
}